Check if the dynamic index is in the valid range