You did the right thing, just so happens that one of your two outs landed on the river after the fold. Right move followed by bad luck (or as I call it, "fate mocking you"). Don't think about it any further. I know it's hard on a hand like this, but when I know I've made the right move I try not to pay any attention to the cards that come out afterward. It can make you second-guess yourself, and pull moves later that you shouldn't.