Well first off, are you sure that you have males and females?!
The gill flaring and head shaking is usually a sign of aggression, but, if you have a male and female that have paired off, they will do this to their tankmates when they are getting ready to spawn as well as during and after spawning. It's a territorial warning. Have two of them marked out a space, guarding it from the other fish?