Sorry to say, but there are no hard and fast answers to this question.
Basically you have two things going on when figuring out whether using an interpolated melody/tune without permission is copyright infringement:
First, it has to be proven that there is "substantial similarity" to the original and that you had access to the original. Access usually isn't a question unless the original song was never released, or if it's so rare that it's possible you've never heard it before and just happened to make a similar melody completely on your own. "Substantial similarity" is whether your average Joe could listen to both tunes side by side and recognize that one was taken from the other.
If those two are proven, then the question becomes whether the use of the melody is allowed by Fair Use. That is determined by looking at four factors:
1. the purpose and character of the use, including whether such use is of a commercial nature or is for nonprofit educational purposes;
2. the nature of the copyrighted work;
3. the amount and substantiality of the portion used in relation to the copyrighted work as a whole; and
4. the effect of the use upon the potential market for or value of the copyrighted work.
Obviously these can be interpreted in widely different ways. However, if you are selling your tracks, the third factor is typically the most important. There is no "magic number" of notes you can use from a melody before it is infringement. For example, if you replayed the theme from "Close Encounters of the Third Kind", you'd only be playing five notes, but those notes are substantially the entire piece.
Finally, there's also the question of whether the melody in question is sufficiently original to warrant protection. For example, you could make a song that follows the chord progression of Pachabel's Canon (as tons of artists have done), but you couldn't then sue someone for using the same progression later since it's so common in music.