O(N)-matrix difference equations and a nested Bethe ansatz