How large is the range of 'same origin' when determining whether two organs are analogous or homologous?
There is no limit: the ribosomes in your cells and the ribosomes in a palm tree are homologous structures, because both you and a palm tree inherited that structure from your last common ancestor, an unicellular eukaryote, more than 1 billion years ago.
That being said, the question in your link (and several other sources) gives an incorrect definition of homology and homoplasy (or analogy). Homology and homoplasy are not defined for &quot;the function of the organ&quot; or anything like that.
First, both terms apply to structures, which have a different meaning in phylogenetic systematics and evolutionary biology. A structure can be:

Morphological
Physiological
Biochemical
Comportamental (ethological)

Thus, we are not necessarily talking about organs or morphology when we define homology and homoplasy.
The difference between homology and homoplasy is very simple:

Homology: a similarity due to common ancestry.
Homoplasy: a similarity not due to common ancestry.

So, in my example using ribosomes, that similarity (&quot;presence of 80S ribosome&quot;) regarding you and a palm tree is due to your (ours) common ancestry.
On the other hand, the thermoregulation in mammals and in birds (and probably other dinosaurs, not only birds) is an example of homoplasy, because the common ancestor of mammals and birds, an early amniote, was probably not capable of thermoregulation. Notice that here the structure is not a morphological one, but a physiological one. Another example using physiology is the pH of the blood: the pH of my blood and the pH of your blood is the same (7.4) because we inherited that feature from our common ancestor. Thus, it's a homology.
Sometimes the situation is tricky. Is the wing of a bat and the wing of a pigeon an example of homology or homoplasy? Since the common ancestor of bats and birds didn't have wings, and both bats and birds developed wings independently in their evolutionary histories, it's an case of homoplasy (analogy). What causes confusion here is that, in both cases, the wing is a modified anterior limb, and the presence of an anterior limb in bats and pigeons is an homology. The &quot;limb&quot; is a homology, not the &quot;wing&quot;.
And that brings us to the case of sharks and whales. If the pectoral fin of a shark derives from the same structure that formed the anterior limb of the first sarcopterygii, then you can say (as several systematists say) that the pectoral fin of a shark and the anterior limb of a whale are homologous structures.
Summarising: given two organisms, Y and X

X and Y share a given feature;
find the last common ancestor of X and Y (it doesn't matter how long ago in the past)
did that ancestor have the feature? Did it transmit the feature to both its descendants?

If the answer to that last question is &quot;yes&quot;, it's an homology. If &quot;no&quot;, it's an homoplasy (analogy).