The idiom is based on the honor shown to cows in Hinduism. It is thought to have started in America in the early 20th century. Similar idioms are used in many other languages. Saying "holy cow!" when surprised may be another example.