These words come from the first stanza of "Evening Solace" by Charlotte Brontë. Though mainly known as a novelist, she also wrote some pretty good poetry, and this is undoubtedly one of her better efforts.
When Brontë says that the human heart has hidden treasures, she simply means that everyone has their own little secrets, hopes, and dreams, which it is important to keep to oneself. Otherwise, if they are revealed, if we tell other people about them, their charms will be broken. They will no longer be secret and therefore no longer be treasured.
The message that Brontë hopes to convey in this poem is that solitude is perfectly fine. For many people, solitude is synonymous with loneliness or isolation. But Brontë sees things differently. She regards solitude as a condition that brings comfort to the individual. It can allow one to discover all kinds of things about oneself, far from the madding crowd of humanity beneath which most of us are submerged at some point in our lives.
In what Brontë describes as "the hours of lonely musing" we often find that "The heart's best feelings gather home." Being alone, then, far from being a bad thing, can actually be of benefit as it generates the best feelings, feelings of love and warmth.
That being the case, if we stick to Brontë's sage advice and keep our "hidden treasures" safely locked away inside our hearts, then there is no reason whatsoever why our individual life stories should have an unhappy ending.