The phrase is used for saying that it's better to hold onto something one has already than to risk losing it by trying to attain something better. It suggests that you should keep what you have and not risk losing it by going after more.
Possibly deriving from sources as old as the ancient Middle East, with the 6th century BCE Proverbs of Ahiqar including "a sparrow in thy hand is better than a thousand sparrows flying". Also it is found in English in John Capgraveās The Life of St Katharine of Alexandria, 1450.