The Natural and Legal Father of Joseph
Heli (Gr. HELEI--Luke 3:23). In Luke he is said to be the father of Joseph, while in Matthew, Jacob was Joseph's father.
The most probable explanation of this seeming contradiction is afforded by having recourse to the levirate law among the Jews, which prescribes that when a man dies childless his widow "shall not marry to another; but his brother shall take her, and raise up seed for his brother" (Deut., xxv, 5).
If brothers dwell together, and one of them dies and has no son, the widow of the dead man shall not be married to a stranger outside the family; her husband's brother shall go in to her, take her as his wife, and perform the duty of a husband's brother to her.
Deuteronomy 25:5, NKJV
The child, therefore, of the second marriage is legally the child of the first (Deut., xxv, 6). Heli having died childless, his widow became the wife of his brother Jacob, and Joseph was the offspring of the marriage, by nature the son of Jacob, but legally the son of Heli. It is likely that Matthew emphasized the natural, and Luke the legal descent.
Mary was the daughter of Jacob, and Joseph was the son of Jacob's brother, Heli. Mary and Joseph were therefore first cousins, and both of the house of David. Jacob, the elder, having died without male issue, transmitted his rights and privileges to the male issue of his brother Heli, Joseph, who according to genealogical usage was his descendant.
-A. Hervey, Bishop of Bath and Wells
Genealogies of Our Lord Jesus Christ