Let n be a positive integer, F be a non-Archimedean locally compact field of odd residue characteristic p and G be an inner form of GL(2n,F). This is a group of the form GL(r,D) for a positive integer r and division F-algebra D of reduced degree d such that rd=2n. Let K be a quadratic extension of F in the algebra of matrices of size r with coefficients in D, and H be its centralizer in G. We study selfdual cuspidal representations of G and their distinction by H from the point of view of type theory. Given such a representation pi of G, we compute the value at 1/2 of the epsilon factor of the restriction of the Langlands parameter phi of pi to the Weil group of K, denoted e(K,phi). When F has characteristic 0, we deduce that pi is H-distinguished if and only if phi is symplectic and e(K,phi)=(-1)^r. This proves in this case a conjecture by Prasad and Takloo-Bighash.