Both Matthew 1 and Luke 3 contain genealogies of Jesus. But there is one problem--they are different. Luke's genealogy starts at Adam and goes to David. Matthew's genealogy starts at Abraham and goes to David. When the genealogies arrive at David, they split with David's sons: Nathan (Mary's side) and Solomon (Joseph's side).
There is no discrepancy because one genealogy is for Mary and the other is for Joseph. It was customary to mention the genealogy through the father even though it was clearly known that it was through Mary.
Some critics may not accept this explanation no matter what reasoning is produced. Nevertheless, they should first realize that the Bible should be interpreted in the context of its literary style, culture, and history. Breaking up genealogies into male and female representations was acceptable in the ancient Near East culture since it was often impolite to speak of women without proper conditions being met: male presence, etc. Therefore, one genealogy is of Mary and the other of Joseph--even though both mention Joseph. In other words, the Mary geneaology was counted "in" Joseph and under his headship. Second, do any critics actually think that those who collected the books of the New Testament, and who believed it was inerrant, were unaware of this blatant differentiation in genealogies? Does anyone actually think that the Christians were so dense that they were unaware of the differences in the genealogy lists, closed their eyes, and put the gospels into the canon anyway hoping no one would notice? Not at all. They knew the cultural context and had no problem with it knowing that one was of Joseph and the other of Mary. Third, notice that Luke starts with Mary and goes backwards to Adam. Matthew starts with Abraham and goes forward to Joseph. The intents of the genealogies were obviously different which is clearly seen in their styles. Luke was not written to the Jews, Matthew was. Therefore, Matthew would carry the legal line (from Abraham through David) and Luke the biological one (from Adam through David). Also, notice that Luke's first three chapters mention Mary eleven times; hence, the genealogy from her. Fourth, notice Luke 3:23, "And when He began His ministry, Jesus Himself was about thirty years of age, being supposedly the son of Joseph, the son of Eli," This designation "supposedly" seems to signify the Marian genealogy since it seems to indicate that Jesus is not the biological son of Joseph.
Finally, in the Joseph genealogy is a man named Jeconiah. God cursed Jeconiah (also called Coniah), stating that no descendant of his would ever sit on the throne of David, "For no man of his descendants will prosper sitting on the throne of David or ruling again in Judah," (Jer. 22:30). But Jesus, of course, will sit on the throne in the heavenly kingdom. The point is that Jesus is not a biological descendant of Jeconiah, but through the other lineage -- that of Mary. Hence, the prophetic curse upon Jeconiah stands inviolate. But, the legal adoption of Jesus by Joseph reckoned the legal rights of Joseph to Jesus as a son, not the biological curse. This is why we need two genealogies: one of Mary (the actually biological line according to prophecy), and the legal line through Joseph.
Again, the early church knew this and had no problem with it. It is only the critics of today who narrow their vision into a literalness and require this to be a "contradiction" when in reality we have an explanation that is more than sufficient.