A series of first principles calculations have been carried out in order to discuss electronic structure, phonon dynamics, structural instabilities and the nature of martensitic transformations of the Heusler alloys Ni$_2$Mn(Ga, Ge, Al) and Co$_2$Mn(Ga, Ge). The calculations show that besides electronic pecularities like Fermi--surface nesting, hybridizing optical and acoustic phonon modes are important for the stabilization of the modulated martensitic structures.