'Tis quite a seasonal question, with the celebration of Jesus' birth rapidly approaching, and Christ's genealogy has long posed difficulties. For one, it's clear the genealogies found in Matthew 1 and Luke 3 have a few discrepancies between them. For instance, 40 generations are represented from Abraham to Joseph in Matthew's genealogy, but in Luke there are 56 from Abraham to Joseph. Matthew stops at Abraham while Luke continues to Adam. Matthew's list includes the names of four women, an unthinkable addition in ancient genealogies--and the four women, Bathsheba, Ruth, Rahab, and Tamar, aren't exactly the kind of women you would typically include in a genealogy. In fact, the names in the two lists don't really agree much at all. Only the names between Abraham and David have any similarity at all. From David to Joseph neither list agrees with the other--even the name of Joseph's father is different.
Scholars generally agree that the authors of the two gospels used their genealogies to prove different points. Matthew's genealogy is contrived, with 14 generations from Abraham to David, 14 from David to the exile, and then 12 to Joseph, making a nice, even 40 in all. Matthew's list is thought to a legalistic description proving Christ's genealogy to David, the lineage of the promised messiah, and then to Abraham, the patriarch of the nation.
Luke, on the other hand, may be more traditional, at least to a point. It is thought that his genealogy is offered to prove that Christ is the messiah for all peoples, thus his path to Adam, who is called "the son of God."
Which brings us to another point regarding Luke. Luke begins with Joseph. However, in the Greek Luke omits the article that should be associated with the name "Joseph." This omission suggests a secondary positioning of Joseph. Because of this and because of the wide differences between the two genealogies, even the earliest historians (e.g., Origen ca 225 AD) concluded that the Lucan text includes Joseph not as a son, but as the son-in-law. Thus the lineage in Luke is not the genealogy of Joseph, but of Mary the mother of Jesus.
Though this explains Luke's genealogy, why would Matthew trace Jesus' lineage through Joseph? There are two possibilities. One non-traditional and non-orthodox answer is that Joseph was in fact the father of Jesus. If this is so, Matthew's contrived genealogy is a legal description showing Jesus as the heir-apparent of the throne of David as the Israelite messiah. This postulate is fraught with problems, especially in regards to church tradition.
The more traditional answer, and likely what Matthew had in mind, was to use the genealogy to prove the Davidic heritage to his intended readers. Matthew's gospel was written specifically for a Jewish audience. Since the genealogies of Jewish families were traced only through the males, to trace the lineage through Mary, though she may have been of the family of David, would be to invalidate the Davidic heritage in the eyes of Jewish readers. Therefore, Matthew had no choice but to trace the lineage through Joseph.
Matthew and Luke wrote their gospels for different audiences, Matthew for the Jew and Luke for the non-Jew. Their genealogies differ because they attempt to validate divergent points. Likely neither is historically accurate, but together they tell the story of a messiah who came for the whole world.