def qzordered(A,B,crit=1.0):
    "Eigenvalues bigger than crit are sorted in the top-left."
    TOL = 1e-10
    def select(alpha, beta):
        return alpha**2>crit*beta**2
    [S,T,alpha,beta,U,V] = ordqz(A,B,output='real',sort=select)
    eigval = abs(numpy.diag(S)/numpy.diag(T))
    return [S,T,U,V,eigval]