I get this too and the big thigh twitch!
I think it's related to sudden hormone changes and, perhaps, a brief lack of oxygen to the muscles? It can be very disconcerting when it happens but I don't think it's dangerous.
Magensium dilates blood vessels so that makes sense it would help.