Check most commentaries and they'll tell you that Jesus' teaching about not throwing your pearls before swine has nothing to do with what he just got through saying about not judging others. One moment he's saying, "Don't judge" and now suddenly he's saying, "Don't throw your pearls before swine." Supposedly this is just some random saying thrown into the mix of Jesus' wise sayings kind of like the Book of Proverbs.
I don't know. My default position is to assume that Jesus doesn't suffer from ADD and doesn't just let random thoughts pop out of his mouth because he happened to see some mangy animals wander by as he was teaching. "So if you don't wish to judge your brother you should first take the log out of your own eye, blah, blah . . . Hey, look at that dog and pig over there! That reminds me, don't give what's holy to dogs or cast your pearls before swine. Anyhow, as I was saying..."
The problem is how to connect up these teachings of Jesus. Here's my best shot at it. Jesus just finished saying that if you want to confront your brother about his sin without judging him, you'll have to deal with your own sin first. In other words, it's going to cost you some. You'll have to humble yourself, take a good look at your own heart, and be unsparing on yourself if you want to be rid of the log in your own eye. It might occur to you that maybe your brother isn't worth the trouble. Maybe you shouldn't bother to put yourself through all that and you should just keep silent. But if that's a brother in the faith you want to help, you will take the trouble because you love him. You're fellow sojourners in the faith, right? You are your brother's keeper.
By contrast do you have the same obligation to those with whom you share no common faith? In Jesus' day the Gentiles were referred to as dogs, godless unbelievers who were outside the covenant. In Matthew 15:26 there is the story where Jesus told the Syrophoenician woman "It is not good to take the children's bread and throw it to the dogs." The Jews, God's covenant people, are referred to as "children" and "brothers" and all sorts of family-type names. But the Gentiles who are outsiders are called "dogs" or even "swine" since pigs are animals that the Jews detest for their filth.
It is one thing to go through the trouble of scouring your soul so that you can see clearly to remove a speck from a brother's eye. It's quite another to attempt to do the same for an unbeliever who has no interest getting specks, logs, two-by-fours, or what have you removed from their eye. A dog who roams wildly or a pig that wallows in the filth of sin may not want to be tamed or pulled out of the mud. Your good advice, your "pearls" as it were, would most likely be rejected and you yourself could wind up torn to pieces.
Most of us have even experienced this when we have tried in our misguided ways to evangelize. Confronting unbelievers about their sin never comes off to them as being "loving" no matter how much we may protest about our good intentions. They only feel judged and patronized and attacked, so they will feel justified in attacking back. That's why Jesus says: save it. You have no obligation to give your pearls to that type of person. "But a natural man does not accept the things of the Spirit of God, for they are foolishness to him, and he cannot understand them because they are spiritually appraised" (1 Cor. 2:14).