Select nearby joints

I have two joints on top of one another.
The user selects one of the joints

The script needs to add the second joint to the selection.

Basically, add select joint that is in a small proximity of selected joint. 

Please help!
Thanks 

global proc selectNearby(float $distance)
{
    string $selection[] = `ls -sl`;
    string $allJoints[] = `ls -type "joint"`;
    vector $pos;
    vector $targetPos;
    string $return[];
    for ($sel in $selection)
    {
        $pos = `xform -query -worldSpace -absolute -translation $sel`;
        for ($joint in $allJoints)
        {
            $targetPos= `xform -query -worldSpace -absolute -translation $joint`;
            $delta = `mag ($targetPos-$pos)`;
            if ($delta < $distance)
            {
                $return[`size($return)`] = $joint;
            }
        }
    }
    select -replace $return;
}