Mary is not mentioned in either Luke 3 or Matthew 1. The only way to bring Mary into the lineage discussion is to assume that one of the two different men identified as Joesph's father (Jacob in Matthew and Heli in Luke) is actually Mary's father and therefore Joseph's father-in-law.
This poses an insoluble dilemma for Protestants who choose to rely only on Scripture when presented with a question that cannot be answered from "Scripture Alone".
So Joseph and Mary were actually cousins although many times removed. Since Heli had no sons, Mary had to find a husband from the tribe of Judah like herself to protect her fathers estate.(See Numbers 36) She also needed a direct descendant of Solomon to perfect her sons claim to the throne of David, since Nathans descendants werent of the Royal line.
Joseph fit the bill on both accounts but like every other descendant of Solomons carried a blood curse disqualifying any biological son of his from ever being King of Israel.(Jeremiah 22:28-30) Since Joseph was not the Lords biological father, he could adopt Him, qualifying Him to be King without passing Him the curse.
Thus, because of the virgin birth, Jesus became the only one in Israel qualified to sit on Davids throne, and remains so to this day.
http://gracethrufaith.com/ask-a-bible-teacher/are-josephs-and-marys-lineage-incorrect/