This is a known bug, and it's not entirely clear if it's the SMS application or Android's SMS implementation itself. You can see the ticket here, which was closed on Jan 29, 2011. The fix has been slow getting out to phones other than the Nexus line because carriers haven't released updates that include it.
One option in the meantime would be to try an alternative SMS app, such as Handcent or ChompSMS. However, though many people say that it does help, others have reported that the bug still persists on 3rd party apps.
There is also an reportedly related bug that causes outgoing messages to be sent to the wrong recipient. The "opening the wrong thread" bug was closed as a duplicate of the "wrong recipient" bug, as the fix for the latter apparently applied to the former (according to Google).