Instead of computing an index mask for all curves, then returning an intersection with the visible curves, just use the visible curves as a universe for the original calculation. Also add another early out for when there are no NURBS curves.
MEM_cnew
MEM_callocN
calloc