"Keeping your head" can still mean don't do anything that will lead you into a dangerous situation. For instance, if someone pulls out in front of you while you're driving, "keeping your head" means you don't try to retaliate.
It can also mean acting calmly in a potentially dangerous situation. If someone is following you, rather than "losing your head" and running or whatever, you instead drive to the police station if you're in the car, or go to an occupied area if you're outside.
Keeping your head is interchangeable with "keeping your wits about you." It usually means calm action in a chaotic situation, rather than doing something stupid which could have serious repercussions.