If $f^2=f$, then $f$ is of constant rank. Let $f$ be a continuous function from $[0,1]$ to set of $n\times n$ matrices i.e. $M(n\times n,\mathbb{R})$ such that $f(t)^2=f(t)$ for all $t$. Then  $f(t)$ has a constant rank for all $t$.
The only thing that I was able to guess conclude here that $f(t)$ has two eigenvalues, namely $0$ and $1$ with the minimal polynomial $x^2-x$, as if the minimal polynomial is $x$ or $x-1$, we are done. 
Now what to do afterwards?
 A: One way to do this is the following: A square matrix $A$ acting on a linear space $V$ with $A^2 = A$ is diagonalizable with $V = \ker A \oplus \operatorname{img} A$. See wikipedia on projectors.
Next thing you need to know, is that you can write down a basis of the kernel of a matrix using polynomials of the matrix’ entries. (I think you can get this from Cramer’s rule alone, but you can also see this by using Gauss elimination, which continuously messes up a matrix, and extracting a basis for the kernel of a matrix from its strict row echelon form). This implies that you can find a basis of eigenvectors of a diagonalizable matrix that polynomially varies in the entries of the matrix because a basis of eigenvectors for the eigenspace of a specific eigenvalue is really just a basis of the kernel of the characteristic matrix with that eigenvalue plugged it.
Hence, you can find a continuous map $g \colon ℝ → \operatorname{GL}_{n×n}(ℝ)$, such that $g(t)^-{1}f(t)g(t)$ is diagonal for all $t ∈ ℝ$. Now $g^{-1}fg$ is also continuous and has constant rank if and only if $f$ has.
So without loss of generally, you may assume that $f$ is constantly diagonal with only possible eigenvalues $0$ and $1$. So …
But, yeah, whatever: Looking at the trace is way cooler.
A: Take the trace of $f(t)$. It's continuous on the one hand and it is the sum of the eigenvalue $1$'s on the other hand, which is just the rank of $f(t) $. 
