You can also use
C_NamePlate.GetNamePlates to get only visible nameplates. A plus to this is it gives you the nameplate.
Lua Code:
function are3EnemiesInRange()
local inRange, unitID = 0
for _, plate in pairs(C_NamePlate.GetNamePlates()) do
unitID = plate.namePlateUnitToken
if UnitCanAttack("player", unitID) and IsItemInRange(63427, unitID) then
inRange = inRange + 1
if inRange >= 3 then return true end
end
end
end