First-principles investigation of the martensitic transition and magnetic properties in Heusler alloys Mg2YZ (Y = Sc, Ti, V, Z = Al, Ga, In)