Tamar (Matthew 1:3) was highly likely a Canaanite (gentile) as Judah liked such women (Genesis 38:2). She pretended to be a whore to entice Judah to have sex with her. Their illicit relationship produced twin boys, one of which was Pharez in Jesus' lineage (Genesis 38).
Rahab (Matthew 1:5) was a non-Israelite harlot living in Jericho. Because she helped Joshua's spies, her life was spared when the city was destroyed (Joshua 2, 6). She ultimately chooses to live among the Israelites (Joshua 6:25) and marries a Jew named Salmon (see also Luke 3:32 - 33). They produce a child named Boaz.
Boaz, mentioned above, added the third female gentile to Jesus' lineage when he married Ruth the Moabitess (Ruth 4, Matthew 1:5). The son they produced, Obed, made them the great-grandparents of King David.
Bathsheba (Matthew 1:6), though not listed by name, is referred to as "the one who had been wife of Uriah." She was the incredibly beautiful and gentile wife of Uriah the Hittite. King David arranged to have Uriah killed in battle in order to cover up his affair with her (2Samuel 11, 12:24). David and Bathsheba ultimately produced several children, one of which was King Solomon in Matthew's lineage.
Missing females
Interestingly, although Matthew lists four females, he leaves out several other important ones. These missing women include Sarah (Abraham's wife), Rebekah (Isaac's wife) and Leah (Jacob's wife who gave birth to Judah).
What about Luke?
Luke's lineage of Christ does not record any women. This is in spite of the fact that it shows Jesus' genetic (biological) lineage through his mother Mary back to King David (through David's son Nathan and not Solomon, 2Samuel 5:14) all the way to Adam and God!
Luke, in spite of lineages traditionally being traced strictly through males, is able to list Jesus' bloodline through a woman like Mary through two semantic tricks. The first trick he employs uses the phrase "the son of Joseph" (Luke 3:23) as a substitution for Mary. The second trick was that while Joseph was not the son of Heli (Joseph's father was Jacob, Matthew 1:15) he was Heli's son-in-law.
A more modern and clearer translation of Luke 3:23 would be, "And Jesus Himself began to be about thirty years old, the son of Mary, whose father was Heli . . . ".
Conclusion
God, who is not a respecter of persons (Acts 10:34), uses anyone he wishes to fulfill his will. He decided, in his wisdom, to use four unique non-Israelite women, three of which were involved in illicit sex, to produce the legal lineage of Jesus found in Matthew 1.