Where does scripture indicate that Mary is of the Davidic line?
Compare Matt. 1 :16, "And Jacob begat Joseph the husband of Mary, of whom was born Jesus, who is called Christ." with Luke 3:23, "And Jesus himself began to be about thirty years of age, being (as was supposed) the son of Joseph, which was the son of Heli,". The notes of the commentators translate "son of Heli" to be "son in law of Heli", because as you rightly say, it is through the father that the name is passed legally.